<?php

namespace app\common\serve;

use think\Db;
use think\Exception;
use think\Request;
use think\Validate;

/**
 * 用户业务
 * Class User
 * @package app\common\serve
 */
class User extends Serve
{

    /**
     * 收货地址
     * @param $params
     * @return array
     */
    public static function address($params)
    {

        $flag = model('UserAddress')->save($params);

        return $flag ? ['code' => 1, 'msg' => '设置成功', 'data' => ''] : ['code' => 1, 'msg' => '设置失败', 'data' => ''];
    }

    /**
     * 加密支付密码
     * @param string $pass 密码明文
     * @return string 密码密文
     */
    public static function encryptPayPass($pass)
    {
        return !empty($pass) ? password_hash($pass, 1) : '';
    }

    /**
     * 验证支付密码
     * @param string $pass 密码明文
     * @return bool
     */
    public static function checkPayPass($uid, $pass)
    {
        $encrypt_pass = Db::name('user')->where(['id' => $uid])->value('pay_pass');
        if (empty($encrypt_pass)) return 0;
        return $encrypt_pass === self::encryptPayPass($pass);
    }

    /**
     * 加密用户密码
     * @param $user_pass
     * @return bool|string
     */
    public static function encryptUserPass($user_pass)
    {
        return password_hash($user_pass, 1);
    }

    /**
     * 设置支付密码
     * @param $uid
     * @param $pass
     * @return int
     */
    public static function setPayPass($uid, $pass)
    {
        return db('user')->where(['id' => intval($uid)])->setField('pay_pass', self::encryptPayPass($pass));
    }

    /**
     * 重置密码
     * @param $phone
     * @param $password
     * @return array
     * @throws Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public static function resets($phone, $password)
    {
        if (checkPhone($phone)) {
            $user = Db::name('user')->field('id,user_pass')->where(['phone' => $phone])->find();
        } else {
            $user = Db::name('user')->field('id,user_pass')->where(['id' => $phone])->find();
        }

        if (!$user['id']) return ['code' => 0, 'msg' => '用户未注册'];

        if (password_verify($password, $user['user_pass'])) return ['code' => 0, 'msg' => '新密码和原密码不得相同，请重新输入'];

        $flag = Db::name('user')->where(['id' => $user['id']])->update(['user_pass' => self::encryptUserPass($password)]);

        return $flag ? ['code' => 1, 'msg' => '重置成功'] : ['code' => 0, 'msg' => '重置失败'];
    }


    /**
     * 提现申请
     * @param $params
     * @return array
     * @throws Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public static function withdraw($params)
    {
        //验证
        if (!isset($params['uid']) || $params['uid'] < 1) {
            return ['code' => 0, 'msg' => '用户ID必须'];
        }

        $withdraw_min = config('withdraw_min');
        if (!isset($params['money']) || $params['money'] < $withdraw_min) {
            return ['code' => 0, 'msg' => '提现金额必须大于' . $withdraw_min . '元'];
        }
        if ($withdraw_min % 100 !== 0) return ['code' => 0, 'msg' => '提现金额必须是整百数目'];

        $user = Db::name('user')->field('id,user_pass')->where(['id' => $params['uid']])->find();
        if (!$user) return ['code' => 0, 'msg' => '用户不存在'];

        //验证密码
        if (!password_verify($params['password'], $user['user_pass'])) return ['code' => 0, 'msg' => '密码不正确，请重新输入'];

        $account_money = Db::name('user_money')->where(['uid' => $params['uid']])->value('account_money');

        if ($account_money < $params['money']) {
            return ['code' => 0, 'msg' => '您的账户余额不够提现哦'];
        }

        //计算手续费
        $fee_rate = config('withdraw_fee');
        if ($fee_rate > 0) {
            $fee = $params['money'] * $fee_rate;
        } else {
            $fee = 0;
        }

        $data = [
            'uid' => $params['uid'],
//            'type' => $params['type'],
            'withdraw_money' => $params['money'],
            'withdraw_paid_money' => $params['money'] - $fee,
            'withdraw_fee' => $fee,
            'account_money' => $account_money - $params['money'],//计算提现时账户余额
            'create_time' => $_SERVER['REQUEST_TIME'],
            'ip' => get_client_ip(),
        ];

        Db::startTrans();

        $id = Db::name('user_withdraw')->insertGetId($data);
        $result = self::memberMoneyLog($params['uid'], 4, -$params['money'], '提现冻结');
        $msg_id = Db::name('user_msg')->insertGetId([
            'uid' => $params['uid'],
            'title' => '提现申请',
            'info' => '尊敬的用户，您的提现申请已成功，请耐心等待财务审核，详情请查看是否到账。',
            'create_time' => $_SERVER['REQUEST_TIME']
        ]);;

        if ($id && $result && $msg_id) {
            Db::commit();
            return ['code' => 1, 'msg' => '提现申请成功，请等待财务审核，预计T+1工作日即可到账'];
        } else {
            Db::rollback();
            trace(__METHOD__ . ' 提现申请失败 ： ' . json_encode($params) . '-' . $id . '-' . $result . '-' . $msg_id, 'error');
            return ['code' => 0, 'msg' => '提现申请失败，请联系客服MM处理！'];;
        }
    }


    /**
     * 提现审核
     * @param array $params
     * @return array
     * @throws Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public static function withdrawAudit($params = [])
    {
        $id = $params['id'];
        $uid = $params['uid'];

        $withdraw = Db::name('user_withdraw')->where(['id' => $id, 'uid' => $uid])->find();
        if (!$withdraw) return ['code' => 0, 'msg' => '无此提现记录', 'data' => ''];

        if (empty($params['deal_info']) || $params['admin_uid'] < 1) {
            return ['code' => 0, 'msg' => '提现备注信息必填', 'data' => ''];
        }

        if ($params['admin_uid'] != config('user_administrator')) {
            return ['code' => 0, 'msg' => '超级管理员才可以审核提现', 'data' => ''];
        }

        if (!in_array($params['withdraw_status'], [2, 4])) {
            return ['code' => 0, 'msg' => '提现审核状态不正确', 'data' => ''];
        }

        /**
         * 判断状态
         */
        switch ($params['withdraw_status']) {
            case 2: //提现通过

                Db::startTrans();
                $withdraw_flag = Db::name('user_withdraw')->where(['id' => $id, 'uid' => $uid])->update([
                    'withdraw_fee' => $params['withdraw_fee'],
                    'withdraw_paid_money' => $params['withdraw_paid_money'],
                    'withdraw_status' => 2,

                    'deal_uid' => $params['admin_uid'],
                    'deal_name' => $params['admin_username'],
                    'deal_time' => $_SERVER['REQUEST_TIME'],
                    'deal_info' => $params['deal_info']
                ]);

                $money_flag = self::memberMoneyLog($uid, 3, $withdraw['withdraw_money'],
                    '提现审核成功，扣除手续费' . $params['withdraw_fee'] . '元，实际到账' . $params['withdraw_paid_money'] . '元',
                    $params['admin_uid']);

                $msg_id = Db::name('user_msg')->insertGetId([
                    'uid' => $params['uid'],
                    'title' => '提现审核通过',
                    'info' => '尊敬的用户，财务已经审核通过并给您发钱啦，请尽快查看是否到账。',
                    'create_time' => $_SERVER['REQUEST_TIME']
                ]);

                if ($withdraw_flag && $money_flag && $msg_id) {
                    Db::commit();

                    //平台账户加钱
                    if ($params['withdraw_fee'] > 0) {
                        Plat::changeMoney(1, 2, $params['withdraw_fee'], '提现审核成功，手续费收入' . $params['withdraw_fee'] . '元', $params['uid']);
                    }

                    return ['code' => 1, 'msg' => '提现审核成功', 'data' => ''];
                } else {
                    Db::rollback();
                    trace(__METHOD__ . '提现审核失败:' . json_encode($params) . '-' . $withdraw_flag . '-' . $money_flag . '-' . $msg_id, 'error');
                    return ['code' => 0, 'msg' => '提现审核处理失败，请联系开发者！', 'data' => ''];
                }
                break;
            case 4: //提现驳回

                Db::startTrans();
                $withdraw_flag = Db::name('user_withdraw')->where(['id' => $id, 'uid' => $uid])->update([
                    'withdraw_fee' => $params['withdraw_fee'],
                    'withdraw_paid_money' => $params['withdraw_paid_money'],
                    'withdraw_status' => 4,

                    'deal_uid' => $params['admin_uid'],
                    'deal_name' => $params['admin_username'],
                    'deal_time' => $_SERVER['REQUEST_TIME'],
                    'deal_info' => $params['deal_info']
                ]);
                $money_flag = self::memberMoneyLog($uid, 10, $withdraw['withdraw_money'], '您的提现被驳回，请检查提现信息是否正确或联系客服。', $params['admin_uid']);

                $msg_id = 1;

                if ($withdraw_flag && $money_flag && $msg_id) {
                    Db::commit();
                    return ['code' => 1, 'msg' => '提现驳回成功', 'data' => ''];
                } else {
                    Db::rollback();
                    trace(__METHOD__ . '提现驳回失败:' . json_encode($params) . '-' . $withdraw_flag . '-' . $money_flag . '-' . $msg_id, 'error');
                    return ['code' => 0, 'msg' => '提现驳回失败', 'data' => ''];
                }

                break;
            default :
                trace(__METHOD__ . ' 提现状态不正确：' . json_encode($params, JSON_UNESCAPED_UNICODE), 'error');
                return ['code' => 0, 'msg' => '提现状态不正确！', 'data' => ''];
                break;
        }
    }

    /**
     * 提现撤销
     * @param array $param
     * @return bool
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public static function withdrawCancel($param = [])
    {
        $where = [
            'id' => $param['id'],
            'uid' => $param['uid'],
            'withdraw_status' => 1
        ];

        $res = db('user_withdraw')->where($where)->find();
        if (empty($res)) return false;

        Db::startTrans();

        $flag = db('user_withdraw')->where($where)->setField('withdraw_status', 4);
        $money_flag = User::memberMoneyLog($param['uid'], 5, $res['withdraw_money'], '撤消提现');

        if ($flag && $money_flag) {
            Db::commit();
            return true;
        } else {
            Db::rollback();
            return false;
        }
    }

    /**
     * 账户资金变更
     * @param int $uid
     * @param int $type
     * @param int $amoney
     * @param string $info
     * @param int $target_uid
     * @param string $target_uname
     * @param string $remark
     * @return bool
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public static function memberMoneyLog($uid = 0, $type = 0, $amoney = 0, $info = '', $target_uid = 0, $target_uname = '', $remark = '')
    {
        $amoney = floatval($amoney);
        if (empty($amoney)) return false;

        $db = db('user_money');
        $MM = $db->field("money_freeze,money_collect,account_money")->where(['uid' => $uid])->find();
        if (!is_array($MM)) $db->insertGetId(['uid' => $uid]);

        if ($uid > 0 && $target_uid > 0) {
            $target_uid = $uid;
            $tname = '@自己@';
        }

        if ($target_uid == 0 && $target_uname == '') {
            $target_uid = 0;
            $tname = '@财务@';
        }

        $data['uid'] = $uid;
        $data['type'] = $type;
        $data['info'] = $info;
        $data['target_uid'] = $target_uid;
        $data['target_uname'] = $tname;
        $data['add_time'] = $_SERVER['REQUEST_TIME'];
        $data['add_ip'] = get_client_ip();
        $data['remark'] = $remark;

        switch ($type) {

            case 1 : //自动充值成功 +钱
            case 2: //后台手动充值成功 +钱
            case 8: //返佣加钱
                $data['affect_money'] = $amoney;
                $data['account_money'] = self::ifEmpty($MM['account_money']) + ($amoney);
                $data['collect_money'] = self::ifEmpty($MM['money_collect']);
                $data['freeze_money'] = self::ifEmpty($MM['money_freeze']);
                break;

            case 3: //提现成功 +钱
                $data['affect_money'] = $amoney;
                $data['account_money'] = self::ifEmpty($MM['account_money']);
                $data['collect_money'] = self::ifEmpty($MM['money_collect']);
                $data['freeze_money'] = self::ifEmpty($MM['money_freeze']) - ($amoney);
                break;

            case 4 : //提现冻结中
            case 5 : //投资冻结中
                $data['affect_money'] = $amoney;
                $data['account_money'] = self::ifEmpty($MM['account_money']) + ($amoney);
                $data['collect_money'] = self::ifEmpty($MM['money_collect']);
                $data['freeze_money'] = self::ifEmpty($MM['money_freeze']) - ($amoney);
                break;

            case 6 : //投资成功
                $data['affect_money'] = $amoney;
                $data['account_money'] = self::ifEmpty($MM['account_money']);
                $data['collect_money'] = self::ifEmpty($MM['money_collect']) + ($amoney);
                $data['freeze_money'] = self::ifEmpty($MM['money_freeze']) - ($amoney);
                break;

            case 11 : //出售回款利息
            case 7 : //出售回款本金
                $data['affect_money'] = $amoney;
                $data['account_money'] = self::ifEmpty($MM['account_money']) + ($amoney);
                $data['collect_money'] = self::ifEmpty($MM['money_collect']) - ($amoney);
                $data['freeze_money'] = self::ifEmpty($MM['money_freeze']);
                break;

            case 10 : //提现驳回
                $data['affect_money'] = $amoney;
                $data['account_money'] = self::ifEmpty($MM['account_money']) + $amoney;
                $data['collect_money'] = self::ifEmpty($MM['money_collect']);
                $data['freeze_money'] = self::ifEmpty($MM['money_freeze']) - $amoney;
                break;

            //单独操作三个字段
            case 71 :
                $data['affect_money'] = $amoney;
                $data['account_money'] = self::ifEmpty($MM['account_money']) + $amoney;
                $data['collect_money'] = self::ifEmpty($MM['money_collect']);
                $data['freeze_money'] = self::ifEmpty($MM['money_freeze']);
                break;

            case 72://单独操作冻结金额
                $data['affect_money'] = $amoney;
                $data['account_money'] = self::ifEmpty($MM['account_money']);
                $data['collect_money'] = self::ifEmpty($MM['money_collect']);
                $data['freeze_money'] = self::ifEmpty($MM['money_freeze'] + $amoney);
                break;

            case 9: //加入代收利息
            case 73://单独操作待收金额
                $data['affect_money'] = $amoney;
                $data['account_money'] = self::ifEmpty($MM['account_money']);
                $data['collect_money'] = self::ifEmpty($MM['money_collect']) + ($amoney);
                $data['freeze_money'] = self::ifEmpty($MM['money_freeze']);
                break;

//            case 71://单独操作可用余额
//            default:
//                $data['affect_money'] = $amoney;
//                $data['account_money'] = self::ifEmpty($MM['account_money']) + $amoney;
//                $data['collect_money'] = self::ifEmpty($MM['money_collect']);
//                $data['freeze_money'] = self::ifEmpty($MM['money_freeze']);
//                break;
        }

        //获取待收金额 < -10 则认为异常 TODO:这个暂时不打开
        if ($data['collect_money'] < -5) return 0;
        if ($data['account_money'] < -5) return 0;
        if ($data['freeze_money'] < -1) return 0;

        //如果出现余额为负的，且是小金额，补差价 sxc
        if ($data['collect_money'] < 0 && $data['collect_money'] > -0.05) {
            $data['collect_money'] = 0;
        }

        Db::startTrans();

        $new_id = db('user_money_log')->insertGetId($data);

        //帐户更新
        $xid = $db->where(['uid' => $uid])->update([
            'money_freeze' => $data['freeze_money'],
            'money_collect' => $data['collect_money'],
            'account_money' => $data['account_money']
        ]);

        if ($new_id && $xid) {
            Db::commit();
            return true;
        } else {
            Db::rollback();
            return false;
        }
    }

    /**
     * 是否为空
     * @param $tar
     * @param int $def
     * @return int
     */
    public static function ifEmpty($tar, $def = 0)
    {
        return empty($tar) ? $def : $tar;
    }

    /**
     * 登陆
     * @param string $username
     * @param string $password
     * @param int $type
     * @return bool|int
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function login($username = '', $password = '', $type = 3)
    {

        $map = [];

        if (Validate::is($username, 'email')) {
            $type = 2;
        } elseif (checkPhone($username)) {
            $type = 3;
        }

        switch ($type) {
            case 1:
                $map['user_name'] = $username;
                break;
            case 2:
                $map['email'] = $username;
                break;
            case 3:
                $map['phone'] = $username;
                break;
            case 4:
                $map['id'] = $username;
                break;
            case 5:
                $map['openid'] = $username;
                break;
            default:
                return 0;    //参数错误
        }

        $user = model('User')->where($map)->find();

        if (isset($user['id']) && $user['id'] > 0 && $user['status'] == 1) {
            if ($type == 5) { //微信验证openid
                return self::autoLogin($user); //更新用户登录信息
            } else {
                //验证密码
                if (password_verify($password, $user['user_pass'])) {
                    return self::autoLogin($user); //更新用户登录信息 登录成功，返回用户ID
                } else {
                    return -2; //密码错误
                }
            }
        }

        return -1; //用户不存在或被禁用
    }

    /**
     * 用户注册
     * @param array $params
     * @return array|bool
     */
    public static function register($params = [])
    {
        Db::startTrans();
        try {

            $userDB = Db::name('user');
            $nextUid = ($userDB->max('id') + 1);

            $data = [
                'phone' => $params['phone'],
                'user_name' => 'user' . mt_rand(100000, 9999999),
                'user_pass' => self::encryptUserPass($params['password']),
                'pay_pass' => self::encryptPayPass(substr($params['phone'], -1, 6)),  //password_hash(substr($params['phone'], -1, 6), PASSWORD_DEFAULT),
                'email' => '',
                'reg_time' => $params['time'],
                'reg_ip' => $params['ip'],
                'reg_way' => $params['way'],
                'recommend_id' => intval($params['invite']),
                'invite_code' => authcode($nextUid . $params['phone'], 'ENCODE'),
            ];

            $uid = $userDB->insertGetId($data);
            trace('register sql :' . $userDB->getLastSql(), 'error');

            $info_flag = Db::name('user_info')->insert(['uid' => $uid]);
            $money_flag = Db::name('user_money')->insert(['uid' => $uid]);

            $msg = Db::name('user_msg')->insertGetId([
                'title' => '注册成功',
                'info' => '感谢您注册本平台, 您的初始支付密码是您手机号后6位，请及时修改！',
                'create_time' => $params['time']
            ]);

            if ($uid && $info_flag && $money_flag && $msg) {
                Db::commit();

                trace('注册成功：' . json_encode($params), 'error');

                $user = $userDB->where(['id' => $uid])->find();
                $user_id = self::autoLogin($user);
                return ['code' => 1, 'msg' => '注册成功', 'data' => $user_id];
            } else {
                Db::rollback();
                trace('注册失败：' . json_encode($params), 'error');
                return ['code' => 0, 'msg' => '注册失败'];
            }

        } catch (Exception $e) {
            Db::rollback();
            trace('注册异常：' . json_encode($params), 'error');
            return ['code' => 0, 'msg' => '注册异常'];
        }
    }

    /**
     * 自动登录用户
     * @param $user
     * @return mixed
     */
    private static function autoLogin($user)
    {
        /* 更新登录信息 */
        Db::name('user_login')->insertGetId(['uid' => $user['id'], 'add_time' => $_SERVER['REQUEST_TIME'], 'ip' => Request::instance()->ip()]);

        /* 记录登录SESSION和COOKIES */
        $auth = [
            'uid' => $user['id'],
            'username' => $user['user_name'],
            'last_login_time' => $_SERVER['REQUEST_TIME'],
        ];

        session('user_auth', $auth);
        session('user_auth_sign', data_auth_sign($auth));

        return $user['id'];
    }

    /**
     * 注销
     */
    public static function logout()
    {
        session('user_auth', null);
        session('user_auth_sign', null);
    }

    /**
     * 人工充值
     * @param $params
     * @return array
     * @throws Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public static function ManualRecharge($params)
    {

        //验证
        if (!isset($params['uid']) || $params['uid'] < 1) {
            return ['code' => 0, 'msg' => '用户ID必须'];
        }

        if (!isset($params['phone']) || !checkPhone($params['phone'])) {
            return ['code' => 0, 'msg' => '手机号格式不正确'];
        }

        //验证用户是否存在
        if (Db::name('user')->where(['id' => $params['uid'], 'phone' => $params['phone']])->count() < 1) {
            return ['code' => 0, 'msg' => '用户不存在'];
        }

        if (!isset($params['money']) || $params['money'] < 1) {
            return ['code' => 0, 'msg' => '充值金额必须大于0'];
        }

        if (isset($params['fee']) && $params['fee'] > 0) {
            $params['money'] = $params['money'] - $params['fee'];
        } else {
            $params['fee'] = 0;
        }

        //TODO:订单号
        $params['type'] = 1;
        $params['status'] = 1;
        $params['way'] = intval($params['way']);
        $params['order_sn'] = self::createOrderSN('man');
        $params['create_time'] = $_SERVER['REQUEST_TIME'];
        $params['update_time'] = $_SERVER['REQUEST_TIME'];
        $params['ip'] = get_client_ip();

        Db::startTrans();

        $recharge_flag = Db::name('user_recharge')->insertGetId($params);
        $money_flag = self::memberMoneyLog($params['uid'], 2, $params['money'], '系统人工充值', session('admin.uid'));
        $msg_id = Db::name('user_msg')->insertGetId([
            'uid' => $params['uid'],
            'title' => '人工充值成功',
            'info' => '尊敬的用户，系统已经为您人工充值成功一笔' . $params['money'] . '元，详情请查看账户可用余额。',
            'create_time' => $_SERVER['REQUEST_TIME']
        ]);

        if ($params['fee'] > 0) {

        }


        if ($recharge_flag && $money_flag && $msg_id) {
            Db::commit();
            return ['code' => 1, 'msg' => '人工充值成功'];
        } else {
            Db::rollback();
            trace(__METHOD__ . ' 人工充值失败 ： ' . json_encode($params) . '-' . $recharge_flag . '-' . $money_flag . '-' . $msg_id, 'error');
            return ['code' => 0, 'msg' => '人工充值失败，请联系开发者'];
        }
    }

    /**
     * TODO:开发中
     * @param $params
     * @return array
     */
    public static function bindBank($params)
    {
        if (!isset($params['uid'])) return ['code' => 0, 'msg' => '您还未登陆'];
        if (!isset($params['type'])) return ['code' => 0, 'msg' => '提现到账类型没有选择'];
        if (!isset($params['full_name'])) return ['code' => 0, 'msg' => '真实全名不得为空'];
        if (!preg_match('/^[\x{4e00}-\x{9fa5}]+$/u', $params['full_name'])) return ['code' => 0, 'msg' => '真实全名必须是中文'];

        $data = [
            'uid' => $params['uid'],
            'type' => $params['type'],
            'full_name' => $params['full_name'],
            'create_time' => $_SERVER['REQUEST_TIME'],
            'update_time' => $_SERVER['REQUEST_TIME']
        ];
        switch ($params['type']) {
            case 1 :

                $data['bank_name'] = '微信账号';
                $data['card_id'] = $params['card_id'];

                break;
            case 2 :
                if (!isset($params['card_id']) || empty($params['card_id'])) ['code' => 0, 'msg' => '账号必填正确，否则影响提现进度！'];

                $data['bank_name'] = '支付宝账号';
                $data['card_id'] = $params['card_id'];

                break;
            case 3:
                if (!isset($params['card_id']) || empty($params['card_id'])) ['code' => 0, 'msg' => '账号必填正确，否则影响提现进度！'];
                if (!isset($params['bank_name']) || empty($params['bank_name'])) ['code' => 0, 'msg' => '银行必须选择！'];
                if (!isset($params['bank_code']) || empty($params['bank_code'])) ['code' => 0, 'msg' => '银行必须选择！ '];

                $data['card_id'] = $params['card_id'];
                $data['bank_name'] = $params['bank_name'];
                $data['bank_code'] = $params['bank_code'];

                break;
            default :
                return ['code' => 0, 'msg' => '提现到账类型选择错误'];
                break;
        }

        $id = Db::name('user_bank')->insertGetId($data);

        if ($id > 0) {
            return ['code' => 1, 'msg' => '设置提现信息成功'];
        } else {
            return ['code' => 0, 'msg' => '设置提现信息失败，请联系客服'];
        }

    }


}